package com.sun.example;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.Log;
import android.widget.RelativeLayout;

/**
 * @author tianxiaolong
 * time：2019-09-22 15:49
 * description：
 */
public class Utils {



	public static Bitmap createBitmapShader(String text,long color,int textSize){
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		paint.setTextSize(textSize);
		Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
		paint.setTextAlign(Paint.Align.CENTER);
		paint.setColor(color);
		Rect rect = new Rect();
		paint.getTextBounds(text,0,text.length(),rect);
		final int height = fontMetricsInt.bottom+Math.abs(fontMetricsInt.top);
		final int width = (int) paint.measureText(text,0,text.length());
		Bitmap bitmap = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		canvas.drawText(text,width/2,(height+rect.height())/2,paint);
		return bitmap;

	}
}
